﻿/*
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	unsigned n;
	while ( cin>>n && n)
	{
		typedef vector<unsigned> vu;
		vu v;
		v.reserve(n);
		for (unsigned len;n--; v.push_back(len))
			cin>>len;
	
		vu::iterator p=v.begin(), q=v.begin();
		unsigned counter=0;
		while (q!=v.end())
		{
			if(*p==*q)
			{
				counter++;
			}
			else
			{
				counter--;
				if(0==counter)
					p=q+1;		
			}
			q++;
		}
		if(counter)
			cout<<*p<<endl;
	}
	
	return 0;
}
*/
/*
P Stick 
Time Limit:1000MS  Memory Limit:32768K


Description:
There are N sticks, and each stick has a corresponding length. One type of these sticks appears more than N/2 times, which is called P stick. Give you the all the sticks' length, could you find the P stick out?

Input:
The input file contains several test case, each test case starts with a number N ( 3<=N<=100,000), the number of the sticks, followed by a line with n integers len1, len2, len3…lenn(0<=bi<=2^31-1),which is the length of these sticks. The input is terminated by a test case with n = 0. It should not be processed. 
Output:
For each test case, output a line the P stick's length of the corresponding sequence. 
Sample Input:
4
3 4 3 3
7
4 5 4 2 4 4 2
0
Sample Output:
3
4
Hint:
It's a classical high offer interview problem, O(N) algorithm exits. 
*/
#include <stdio.h>
int main()
{
	unsigned n;
	while ( EOF!=scanf("%u", &n) && n)
	{
		int* v= new int[n+1];
		for (unsigned i=0; i<n; i++)
		{
			scanf("%u", v+i);
		}
		const int *p=v, *q=v;
		unsigned counter=0;
		while (q!=(v+n))
		{
			if(*p==*q)
				counter++;
			else
			{
				counter--;
				if(0==counter)
					p=q+1;
			}
			q++;
		}
		if(counter)
			printf("%u\n", *p);
		delete [] v;
		v=NULL;
	}
	
	return 0;
}
/*
#include <stdio.h>
int main()
{
	static char* str="112211331";//aababbbacbb
	const char* p=str, *q=str;
	int count=0;
	while (*q)
	{	
		if(*p==*q)
		{
			count++;
		}
		else
		{
			count--;
			if(0==count)
				p=q+1;		
		}
		q++;
	}
	if(count)
	{
		printf("%c\n", *p);
	}
	
	// 	while (true)
// 	{	
// 		if(*p==*q)
// 		{
// 			count++;
// 		}
// 		else
// 		{
// 			count--;
// 			if(0==count)
// 				p=q+1;		
// 		}
// 		q++;
// 		if(count && '\0'==*q)
// 		{
// 			printf("%c\n", *p);
// 			break;
// 		}
// 	}

	return 0;
}
*/